package logic

import (
	"context"
	"errors"
	"house_srv/models/mysql"

	"house_srv/housesrv"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListHouseLogic {
	return &ListHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListHouseLogic) ListHouse(in *housesrv.ListHouseRequest) (*housesrv.ListHouseResponse, error) {
	// todo: add your logic here and delete this line

	var h mysql.House
	house, err := h.ListHouse()
	if err != nil {
		logx.Error("房源列表展示失败")
		return nil, errors.New("房源列表展示失败")
	}

	return &housesrv.ListHouseResponse{List: house}, nil
}
